package com.shop.controller;

import com.shop.entity.Shop;
import com.shop.fegin.CompanyClient;
import com.shop.fegin.RabbitMqClient;
import com.shop.fegin.entity.Company;
import com.yx.tool.Response;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author yinxing
 * @date 2022-08-05
 */
@RestController
public class VisitController {

    @Resource
    private CompanyClient companyClient;

    @Resource
    private RabbitMqClient rabbitMqClient;

    @Value("${rabbitmq.exchange}")
    private String exchange_name;

    @Value("${rabbitmq.route_key}")
    private String route_key;


    /**
     * 访问自己
     *
     * @param shop
     * @return
     */
    @RequestMapping("/visit")
    public String visit(@RequestBody Shop shop) {
        return shop.getResource() + " visit the shop";
    }

    /**
     * 访问商城
     *
     * @param company
     * @return
     */
    @RequestMapping("/testCompany")
    public String testShop(@RequestBody Company company) {
        return companyClient.visit(company);
    }

    @GetMapping("/hello")
    public String hello() {
        return "hello i am shop !";
    }


    @GetMapping("/send")
    public Response send(String message) throws IOException {
        return rabbitMqClient.send(exchange_name,route_key, message);
    }

}
